﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBModel
{
    public partial class Language
    {
        public override string ToString()
        {
            return string.Format("{0}, {1,-15}, {2,-15}, Antal år:{3,2}",
                LanguageId, LanguageName, LanguageGrade, LanguageYearsOfExperience);
        }
        public string ToHtml()
        {
            return string.Format("{0}<br /> {1}<br /> {2}<br />",
                LanguageName, LanguageGrade, LanguageYearsOfExperience);
        }
    }

    public static class LanguageDB
    {
        public static Language GetLanguageById(int id)
        {
            return DB.Context.Languages
                .Where(l => l.LanguageId == id)
                .SingleOrDefault(s => !s.IsDeleted);
        }

        public static bool DeleteLanguageById(int id)
        {
            Language languageToDelete = GetLanguageById(id);
            if (languageToDelete != null)
            {
                languageToDelete.IsDeleted = true;
                int affectedRows = DB.Context.SaveChanges();
                return (affectedRows > 0);
            }
            return false;
        }
    }
}
